home *** CD-ROM | disk | FTP | other *** search
/ 200 Game / 200GAME2.iso / main.dxr / Internal_187_Play Sound.ls < prev    next >
Encoding:
Text File  |  2003-05-06  |  3.0 KB  |  75 lines

  1. property soundMember, soundChannel, playWhen, loops
  2.  
  3. on beginSprite me
  4.   if (playWhen = "at the beginning of the frame") or (playWhen = "when the sprite first appears") then
  5.     me.playMySound()
  6.   end if
  7. end
  8.  
  9. on endSprite me
  10.   if (playWhen = "at the end of the frame") or (playWhen = "when the sprite leaves the stage") then
  11.     me.playMySound()
  12.   end if
  13. end
  14.  
  15. on mouseEnter me
  16.   if playWhen = "when the cursor moves over the sprite" then
  17.     me.playMySound()
  18.   end if
  19. end
  20.  
  21. on mouseLeave me
  22.   if playWhen = "when the cursor moves off of the sprite" then
  23.     me.playMySound()
  24.   end if
  25. end
  26.  
  27. on mouseDown me
  28.   if playWhen = "when the mouse clicks on the sprite" then
  29.     me.playMySound()
  30.   end if
  31. end
  32.  
  33. on mouseUp me
  34.   if playWhen = "when the mouse button is released over the sprite" then
  35.     me.playMySound()
  36.   end if
  37. end
  38.  
  39. on playMySound me
  40.   soundstatus = sound(soundChannel).status
  41.   if soundstatus = 4 then
  42.     sound(soundChannel).play()
  43.   else
  44.     sound(soundChannel).play([#member: soundMember, #loopCount: loops])
  45.   end if
  46. end
  47.  
  48. on isOKToAttach me, aSpriteType, aSpriteNum
  49.   return 1
  50. end
  51.  
  52. on getPropertyDescriptionList me
  53.   props = [:]
  54.   props[#soundMember] = [#comment: "Sound to play", #format: #sound, #default: EMPTY]
  55.   props[#soundChannel] = [#comment: "Sound channel", #format: #integer, #default: 1, #range: [1, 2, 3, 4, 5, 6, 7, 8]]
  56.   if the currentSpriteNum = 0 then
  57.     whenDefault = "at the beginning of the frame"
  58.     whenRange = ["at the beginning of the frame", "at the end of the frame"]
  59.   else
  60.     whenDefault = "when the mouse clicks on the sprite"
  61.     whenRange = ["when the sprite first appears", "when the sprite leaves the stage", "when the mouse clicks on the sprite", "when the mouse button is released over the sprite", "when the cursor moves over the sprite", "when the cursor moves off of the sprite"]
  62.   end if
  63.   props[#playWhen] = [#comment: "When to play sound", #format: #string, #default: whenDefault, #range: whenRange]
  64.   props[#loops] = [#comment: "Number of loops (0 = forever)", #format: #integer, #default: 1]
  65.   return props
  66. end
  67.  
  68. on getBehaviorTooltip me
  69.   return "Plays a sound based on a frame or sprite event."
  70. end
  71.  
  72. on getBehaviorDescription me
  73.   return "PLAY SOUND" & RETURN & RETURN & "Drop this behavior onto a sprite, the Stage, or the Script channel of the Score to play a sound based on the movement of the playback head or cursor." & RETURN & RETURN & "When used in the Script channel, this behavior can play the sound when the playback head enters or leaves the frame. " & "With sprites, the behavior can react to the beginning or end of the sprite, or to mouse events. " & "Choose a sound, a sound channel, an event to trigger the sound and how many times the sound should play." & RETURN & RETURN & "PARAMETERS:" & RETURN & "* Sound to play - cast member used by behavior" & RETURN & "* Sound channel - which channel to use for playback" & RETURN & "* When to play sound - event to trigger sound" & RETURN & "* Number of loops - how many times sound plays (0 = forever)"
  74. end
  75.